package com.xc.ksxt.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xc.common.object.*;
import com.xc.common.tool.Helper;
import com.xc.db.Tables;
import com.xc.db.tables.ChoiceCopy;
import com.xc.db.tables.DateScore;
import com.xc.db.tables.LibChoice;
import com.xc.db.tables.LibQuestion;
import com.xc.db.tables.PaperCopy;
import com.xc.db.tables.QuestionCopy;
import com.xc.ksxt.entity.ChoiceCopyEntity;
import com.xc.ksxt.entity.DateScoreEntity;
import com.xc.ksxt.entity.LibChoiceEntity;
import com.xc.ksxt.entity.LibQuestionEntity;
import com.xc.ksxt.entity.PaperCopyEntity;
import com.xc.ksxt.entity.PaperEntity;
import com.xc.ksxt.entity.QuestionCopyEntity;
import com.xc.ksxt.service.ChoiceCopyService;
import com.xc.ksxt.service.DateScoreService;
import com.xc.ksxt.service.LibChoiceService;
import com.xc.ksxt.service.LibQuestionService;
import com.xc.ksxt.service.PaperCopyService;
import com.xc.ksxt.service.PaperService;
import com.xc.ksxt.service.QuestionCopyService;
import com.xc.ksxt.vo.PaperCopyVO;
import com.xc.sys.entity.SysDictEntity;
import com.xc.sys.entity.SysOrganizationEntity;
import com.xc.sys.entity.SysUserEntity;
import com.xc.sys.service.SysDictService;
import com.xc.sys.service.SysOrganizationService;
import com.xc.sys.service.SysUserService;
import com.xc.sys.vo.SysUserVO;
import org.apache.commons.lang3.StringUtils;
import org.jooq.Condition;
import org.jooq.Record;
import org.jooq.Result;
import org.jooq.impl.DSL;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Period;
import java.util.*;

@RestController
@RequestMapping("/paperCopy")
public class PaperCopyController {

    @Autowired
    private DateScoreService dateScoreService;
    @Autowired
    private LibQuestionService libQuestionService;
    @Autowired
    private LibChoiceService libChoiceService;
    @Autowired
    private ChoiceCopyService choiceCopyService;
    @Autowired
    private QuestionCopyService questionCopyService;
    @Autowired
    private PaperCopyService paperCopyService;
    private ChoiceCopy CHOICECOPYTB = ChoiceCopy.CHOICE_COPY.as("CHOICECOPYTB");
    private LibQuestion LIBQUESTIONTB = LibQuestion.LIB_QUESTION.as("LIBQUESTIONTB");
    private LibChoice LIBCHOICETB = LibChoice.LIB_CHOICE.as("LIBCHOICETB");
    private QuestionCopy QUESTIONCOPYTB = QuestionCopy.QUESTION_COPY.as("QUESTIONCOPYTB");
    private PaperCopy PAPERCOPYTB = PaperCopy.PAPER_COPY.as("PAPERCOPYTB");
    private DateScore DATESCORETB = DateScore.DATE_SCORE.as("DATESCORETB");
    @CrossOrigin(origins = "*", allowedHeaders = {"*"}, methods = {RequestMethod.GET})
    @RequestMapping({"/getPageList"})
    public LayuiTableResponse<PaperCopyVO> getPageList(HttpServletRequest request) {
        LayuiTableResponse<PaperCopyVO> ltr = new LayuiTableResponse<>();
        
        Condition cond = PAPERCOPYTB.STATE.notEqual(-1);
        String name = request.getParameter("userName");
        String orgId = request.getParameter("orgId");
        String markLevel = request.getParameter("markLevel");
        String userId = request.getParameter("userId");
        Integer limit = Integer.valueOf(request.getParameter("limit"));
        Integer page = Integer.valueOf(request.getParameter("page"));
        if (StringUtils.isNotBlank(userId)) {
        	cond = cond.and(PAPERCOPYTB.CREATE_USER_ID.eq(Integer.valueOf(userId)));
        }else {
        	SysUserEntity me = Helper.getMe(request);
        	if(me.getRoleCode().indexOf("admin")==-1) {
            	cond = cond.and(PAPERCOPYTB.CREATE_USER_ID.eq(Integer.valueOf(me.getId())));
            }
        }
        
        if (StringUtils.isNotBlank(name)) {
        	cond = cond.and(PAPERCOPYTB.NAME.like("%"+name+"%"));
        }
        if (StringUtils.isNotBlank(orgId)) {
        	cond = cond.and(PAPERCOPYTB.CREATE_USER_ID.in( DSL.select(DSL.field("id")).from(Tables.SYS_USER).where(DSL.field("node_org_id").eq( Integer.valueOf(orgId) )).asField() ));
        }
        if (StringUtils.isNotBlank(markLevel)) {
        	cond = cond.and(PAPERCOPYTB.MARK_LEVEL.eq( Integer.valueOf(markLevel) ));
        }
        
        Long count = paperCopyService.count(cond);
        ltr.setCount(count);
        PageInfo<PaperCopyEntity> pageInfo = new PageInfo<>(limit, page);
        Result<Record> list = paperCopyService.select(cond, pageInfo,PAPERCOPYTB.NAME.asc(),PAPERCOPYTB.CREATE_TIME.desc());
        List<PaperCopyVO> paperCopyEntityList = list.into(PaperCopyVO.class);
        for (PaperCopyVO paperCopyEntity : paperCopyEntityList){
            SysUserVO user = SysUserService.getFrameCaches(paperCopyEntity.getCreateUserId());
			if(user!=null){
				paperCopyEntity.setCreateUserName(user==null?"":user.getName());
				String nodeOrgId = user.getNodeOrgId();
				SysOrganizationEntity org = SysOrganizationService.getFromCaches(nodeOrgId);
				paperCopyEntity.setOrgName(org==null?"":org.getName());
			}
            SysDictEntity dict = SysDictService.getFromCaches("mark-level," + paperCopyEntity.getMarkLevel());
            paperCopyEntity.setMarkLevelTxt(dict==null?"":dict.getName());
            paperCopyEntity.setCostMinuteTxt(paperCopyEntity.getCostMinute()==null?"":paperCopyEntity.getCostMinute() + "分钟");
        }
        ltr.setData(paperCopyEntityList);
        return ltr;
    }
    
    @RequestMapping({"/getById"})
    public PaperCopyEntity getById(Long id) {
        PaperCopyEntity entity = paperCopyService.getEntityById(id);
        return entity;
    }

    @RequestMapping({"/save"})
    public ResponseEntity<PaperCopyEntity> save(@RequestBody HashMap<String,String> params, HttpServletRequest request) {
    	ResponseEntity<PaperCopyEntity> res = new ResponseEntity<>();
    	PaperCopyEntity paperCopyEntity = Helper.map2Bean(new PaperCopyEntity(), params);
    	paperCopyService.save(paperCopyEntity);
        return res;
    }
	@CrossOrigin
    @PostMapping({"/createPaper"})
    public JSONObject createPaper(@RequestBody HashMap<String,String> params, HttpServletRequest request) {
    	JSONObject res = new JSONObject();
    	SysUserEntity me = Helper.getMe(request);
		if(me != null){
			res.put("userName",me.getName());
		}
    	res.put("code",0);
    	LocalDate today = LocalDate.now();
    	Long paperId = Long.valueOf(params.get("paperId"));
		Integer userId = Integer.valueOf(params.get("userId"));
		
		Condition cond = PAPERCOPYTB.CREATE_USER_ID.eq(Integer.valueOf(userId))
    			.and(PAPERCOPYTB.PAPER_ID.eq(Long.valueOf(paperId))).and(PAPERCOPYTB.SUBMIT_TIME.isNull());
    	List<PaperCopyEntity> pcList = paperCopyService.select(cond);
    	if(pcList.size()==0) {
    		LocalDateTime now = LocalDateTime.now();
    		PaperEntity paperEntity = PaperService.getFromCaches(paperId);
    		Period gap = Period.between(paperEntity.getBeginDate(),today);
    		int gapDays = gap.getDays() + 1;
    		int yu = gapDays % 7;
    		int weekNo = yu == 0 ? gapDays/7 : gapDays/7 + 1;
        	List<LibQuestionEntity> questionList = libQuestionService.select(LIBQUESTIONTB.LIB_ID.eq(Integer.valueOf(paperEntity.getLibId())));
        	int size = questionList.size();
        	Set<LibQuestionEntity> set = new HashSet<>();
        	PaperCopyEntity pcEntity = new PaperCopyEntity();
        	pcEntity.setCreateTime(now);
        	pcEntity.setCreateUserId(userId + "");
        	pcEntity.setName(paperEntity.getName());
        	pcEntity.setScore(paperEntity.getScore());
        	pcEntity.setOkScore(paperEntity.getOkScore());
        	pcEntity.setResultScore(0);
        	pcEntity.setState(1);
        	pcEntity.setPaperId(paperId + "");
        	pcEntity.setCreateUserId(userId + "");
        	pcEntity.setYearmonth(Integer.valueOf(now.format(Constant.yearmonthDtf)));
        	pcEntity.setWeekNo(weekNo);
        	pcEntity.setHowlong(paperEntity.getHowlong());
        	String pcId = paperCopyService.insert(pcEntity);
        	while(set.size()<paperEntity.getQuestionNum()) {
        		int i = (int)(Math.random() * size);
        		set.add(questionList.get(i));
        	}
        	Iterator<LibQuestionEntity> it = set.iterator();
        	JSONArray arr = new JSONArray();
        	while (it.hasNext()) {
        		LibQuestionEntity entity = it.next();
        		JSONObject qj = new JSONObject();
        		arr.add(qj);
        		qj.put("text",entity.getText());
        		qj.put("score",entity.getScore());
        		qj.put("questionType",entity.getQuestionType());
        		QuestionCopyEntity qce = new QuestionCopyEntity();
        		qce.setCreateTime(now);
        		qce.setCreateUserId(userId + "");
        		qce.setLibId(entity.getLibId());
        		qce.setLibQuestionId(entity.getId());
        		qce.setPaperCopyId(pcId);
        		qce.setPaperId(paperId + "");
        		qce.setQuestionType(entity.getQuestionType());
//        		qce.setScore(entity.getScore());
        		qce.setText(entity.getText());
        		String qcId = questionCopyService.insert(qce);
        		List<LibChoiceEntity> choiceList = libChoiceService.select(LIBCHOICETB.LIB_QUESTION_ID.eq(Long.valueOf(entity.getId())), LIBCHOICETB.INDEX_LETTER.asc());
        		JSONArray arr2 = new JSONArray();
        		for (LibChoiceEntity choice : choiceList) {
        			ChoiceCopyEntity choiceCopyEntity = new ChoiceCopyEntity();
        			choiceCopyEntity.setCreateTime(now);
        			choiceCopyEntity.setText(choice.getText());
        			choiceCopyEntity.setCreateUserId(userId + "");
        			choiceCopyEntity.setIndexLetter(choice.getIndexLetter());
        			choiceCopyEntity.setLibChoiceId(choice.getId());
        			choiceCopyEntity.setLibId(choice.getLibId());
        			choiceCopyEntity.setLibQuestionId(entity.getId());
        			choiceCopyEntity.setQuestionCopyId(qcId);
        			choiceCopyEntity.setAnswerText(choice.getAnswerText());
        			choiceCopyEntity.setSelected(2);
        			choiceCopyEntity.setRight(choice.getRight());
        			String ccId = choiceCopyService.insert(choiceCopyEntity);
        			JSONObject cj = new JSONObject();
        			cj.put("text",choice.getText());
        			cj.put("orderno",choice.getIndexLetter());
        			cj.put("id",ccId);
        			arr2.add(cj);
        		}
        		qj.put("choiceList",arr2);
        	}
        	res.put("score", paperEntity.getScore());
        	res.put("name", paperEntity.getName());
        	res.put("howlong", paperEntity.getHowlong());
        	res.put("createTime", now);
        	res.put("list",arr);
        	res.put("paperCopyId",pcId);
    		return res;
    	}
    	PaperCopyEntity pcEntity = pcList.get(0);
    	JSONArray arr = new JSONArray();
    	List<QuestionCopyEntity> qcList = questionCopyService.select(QUESTIONCOPYTB.PAPER_COPY_ID.eq(Long.valueOf(pcEntity.getId())));
    	for(QuestionCopyEntity qce : qcList) {
    		JSONObject qj = new JSONObject();
    		arr.add(qj);
    		qj.put("text",qce.getText());
    		qj.put("score",qce.getScore());
    		qj.put("questionType",qce.getQuestionType());
    		JSONArray arr2 = new JSONArray();
    		List<ChoiceCopyEntity> ccList = choiceCopyService.select(CHOICECOPYTB.QUESTION_COPY_ID.eq(Long.valueOf(qce.getId())), CHOICECOPYTB.INDEX_LETTER.asc());
    		for(ChoiceCopyEntity cce : ccList) {
    			JSONObject cj = new JSONObject();
    			cj.put("text",cce.getText());
    			cj.put("orderno",cce.getIndexLetter());
    			cj.put("id",cce.getId());
    			cj.put("selected",cce.getSelected());
    			arr2.add(cj);
    		}
    		qj.put("choiceList",arr2);
    	}
    	res.put("name", pcEntity.getName());
    	res.put("howlong", pcEntity.getHowlong());
    	res.put("createTime", pcEntity.getCreateTime());
    	res.put("list",arr);
    	res.put("score", pcEntity.getScore());
    	res.put("paperCopyId",pcEntity.getId());
    	return res;
    }
    @Transactional
    @RequestMapping(value = { "/toResultPage" }, method = { RequestMethod.GET })
	public ModelAndView toResultPage(Model model, HttpServletRequest request) {
    	ModelAndView mav = new ModelAndView("ksxt/paper/ks_result");
    	SysUserEntity me = (SysUserEntity) request.getSession().getAttribute("me");
		if (me == null) {
			mav.setViewName("login-again");
			return mav;
		}
    	String paperCopyId = request.getParameter("paperCopyId");
    	PaperCopyEntity pc = PaperCopyService.getFromCaches(paperCopyId);
		List<QuestionCopyEntity> qList = questionCopyService.select(QUESTIONCOPYTB.PAPER_COPY_ID.eq(Long.valueOf(paperCopyId)), QUESTIONCOPYTB.ID.asc());
		int resultScore = 0;
		for(QuestionCopyEntity qce : qList) {
			List<ChoiceCopyEntity> cList = choiceCopyService.select(CHOICECOPYTB.QUESTION_COPY_ID.eq(Long.valueOf(qce.getId())), CHOICECOPYTB.ID.asc());
			int right = 1;
			String rightAnswer = "";
			for(ChoiceCopyEntity cce : cList) {
				if(cce.getSelected()!=cce.getRight()) {
					right = 2;
				}
				if(cce.getRight()==1) {
					if(rightAnswer.length()>0) {
						rightAnswer += ",";
					}
					rightAnswer += cce.getIndexLetter();
				}
			}
			if(right==1) {
				resultScore += qce.getScore();
			}
			qce.setRightAnswer(rightAnswer);
			qce.setRight(right);
			questionCopyService.update(qce);
		}
		LocalDateTime now = LocalDateTime.now();
		synchronized (pc) {

			if(pc.getSubmitTime()==null) {
				pc.setResultScore(resultScore);
				pc.setSubmitTime(now.minusSeconds(5));
				long costMunite = Duration.between(pc.getCreateTime(),pc.getSubmitTime()).toMillis();
				long yu = costMunite % 60;
				if(yu==0) {
					costMunite = costMunite / 60;
				}else {
					costMunite = costMunite / 60 + 1; 
				}
				pc.setCostMinute(costMunite);
				if(pc.getResultScore().intValue()>=pc.getOkScore().intValue()) {
					pc.setMarkLevel(1);
				}else {
					pc.setMarkLevel(2);
				}
				paperCopyService.update(pc);
				updateDateScore(me, pc, resultScore);
			}
		}
		
		mav.addObject("paperCopyId",paperCopyId);
		mav.addObject("resultScore",resultScore);
		mav.addObject("score",pc.getScore());
		return mav;
	}

	private void updateDateScore(SysUserEntity me, PaperCopyEntity pc, int resultScore) {
		Condition dateScoreCond = DATESCORETB.PAPER_ID.eq(Long.valueOf(pc.getPaperId())).and(DATESCORETB.DATE.cast(LocalDate.class).eq(LocalDate.now()))
				.and(DATESCORETB.USER_ID.eq(Integer.valueOf(me.getId())));
		List<DateScoreEntity> dateScoreList = dateScoreService.select(dateScoreCond, DATESCORETB.DATE.asc());
		if(dateScoreList.size()==1) {
			DateScoreEntity dateScoreEntity = dateScoreList.get(0);
			if(dateScoreEntity.getMaxScore()==null||dateScoreEntity.getMaxScore().intValue()<resultScore) {
				dateScoreEntity.setMaxScore(resultScore);
				dateScoreEntity.setMarkLevel(pc.getMarkLevel());
				dateScoreService.update(dateScoreEntity);
			}
		}
	}

	/**
	 * 交卷
	 * @param request
	 * @return
	 */
	@CrossOrigin
	@Transactional
	@RequestMapping(value = { "/toResult" }, method = { RequestMethod.GET })
	public R toResult(HttpServletRequest request) {
		String paperCopyId = request.getParameter("paperCopyId");
		String createUserId = request.getParameter("createUserId");
		SysUserVO me = SysUserService.getFrameCaches(createUserId);
		PaperCopyEntity pc = PaperCopyService.getFromCaches(paperCopyId);
		List<QuestionCopyEntity> qList = questionCopyService.select(QUESTIONCOPYTB.PAPER_COPY_ID.eq(Long.valueOf(paperCopyId)), QUESTIONCOPYTB.ID.asc());
		int resultScore = 0;
		for(QuestionCopyEntity qce : qList) {
			List<ChoiceCopyEntity> cList = choiceCopyService.select(CHOICECOPYTB.QUESTION_COPY_ID.eq(Long.valueOf(qce.getId())), CHOICECOPYTB.ID.asc());
			int right = 1;
			String rightAnswer = "";
			for(ChoiceCopyEntity cce : cList) {
				if(cce.getSelected()!=cce.getRight()) {
					right = 2;
				}
				if(cce.getRight()==1) {
					if(rightAnswer.length()>0) {
						rightAnswer += ",";
					}
					rightAnswer += cce.getIndexLetter();
				}
			}
			if(right==1) {
				resultScore += qce.getScore();
			}
			qce.setRightAnswer(rightAnswer);
			qce.setRight(right);
			questionCopyService.update(qce);
		}
		synchronized (pc) {
			
			if(pc.getSubmitTime()==null) {
				System.out.println("交卷："+pc.getCreateUserId());
				pc.setResultScore(resultScore);
				pc.setSubmitTime(LocalDateTime.now().minusSeconds(5));
				long costMunite = Duration.between(pc.getCreateTime(),pc.getSubmitTime()).toMinutes();
				pc.setCostMinute(costMunite);
				if(pc.getResultScore().intValue()>=pc.getOkScore().intValue()) {
					pc.setMarkLevel(1);
				}else {
					pc.setMarkLevel(2);
				}
				paperCopyService.update(pc);
				updateDateScore(me, pc, resultScore);
			}
		}
		
		Map<String,Object> map = new HashMap<>();
		map.put("paperCopyId",paperCopyId);
		map.put("resultScore",resultScore);
		map.put("score",pc.getScore());
		return R.success(map,"交卷成功");
	}


	@CrossOrigin
    @GetMapping({"/showResult"})
    public JSONObject showResult(HttpServletRequest request) {
    	JSONObject res = new JSONObject();
    	SysUserEntity me = Helper.getMe(request);
    	if (me!=null){
			res.put("userName",me.getName());
		}
		Long paperCopyId = Long.valueOf(request.getParameter("paperCopyId"));
		PaperCopyEntity paperCopyEntity = PaperCopyService.getFromCaches(paperCopyId);
		List<QuestionCopyEntity> qList = questionCopyService.select(QUESTIONCOPYTB.PAPER_COPY_ID.eq(paperCopyId), QUESTIONCOPYTB.INDEX_LETTER.asc());
    	JSONArray arr = new JSONArray();
    	for(QuestionCopyEntity qce : qList) {
    		JSONObject jobjq = new JSONObject();
    		jobjq.put("text", qce.getText());
    		jobjq.put("score", qce.getScore());
    		jobjq.put("right", qce.getRight());
    		jobjq.put("rightAnswer", qce.getRightAnswer());
    		jobjq.put("questionType", qce.getQuestionType());
    		arr.add(jobjq);
    		List<ChoiceCopyEntity> choiceList = choiceCopyService.select(CHOICECOPYTB.QUESTION_COPY_ID.eq(Long.valueOf(qce.getId())), CHOICECOPYTB.INDEX_LETTER.asc());
    		JSONArray arr2 = new JSONArray();
    		for (ChoiceCopyEntity cce : choiceList) {
    			JSONObject jobjc = new JSONObject();
    			jobjc.put("id", cce.getId());
    			jobjc.put("text", cce.getText());
    			jobjc.put("orderno", cce.getIndexLetter()); 
    			jobjc.put("right", cce.getRight()); 
    			jobjc.put("selected", cce.getSelected()); 
    			jobjc.put("answerText", cce.getAnswerText()); 
    			arr2.add(jobjc);
    		}
    		jobjq.put("choiceList", arr2);
    	}
    	res.put("name", paperCopyEntity.getName());
    	res.put("createTime", paperCopyEntity.getCreateTime());
		if(paperCopyEntity.getCreateUserId()!=null){
			SysUserVO createUser = SysUserService.getFrameCaches(paperCopyEntity.getCreateUserId());
			res.put("createUserName", createUser.getName());
		}else {
			res.put("createUserName", "");
		}

    	res.put("costMinute", paperCopyEntity.getCostMinute());
    	res.put("paperCopyId", paperCopyId);
    	SysDictEntity dict = SysDictService.getFromCaches("mark-level," + paperCopyEntity.getMarkLevel());
    	res.put("markLevel",dict==null?"":dict.getName());
    	res.put("list",arr);
    	return res;
    }
    @CrossOrigin(origins = "*", allowedHeaders = {"*"}, methods = {RequestMethod.GET})
    @GetMapping({"/judgeOk"})
    public JSONObject judgeOk(HttpServletRequest request) {
    	JSONObject res = new JSONObject();
    	Long paperId = Long.valueOf(request.getParameter("paperId"));
		Integer userId = Integer.valueOf(request.getParameter("userId"));
		LocalDate today = LocalDate.now();
		Condition cond = DATESCORETB.USER_ID.eq(userId).and(DATESCORETB.PAPER_ID.eq(paperId)).and(DATESCORETB.DATE.cast(LocalDate.class).eq(today));
		Long dsc = dateScoreService.count(cond);
		if(dsc==0) {
			res.put("code",1);
			res.put("msg","请预先生成得分记录");
			return res;
		}
    	List<PaperCopyEntity> pcList = paperCopyService.select(PAPERCOPYTB.CREATE_USER_ID.eq(Integer.valueOf(userId))
    			.and(PAPERCOPYTB.PAPER_ID.eq(Long.valueOf(paperId))).and(PAPERCOPYTB.SUBMIT_TIME.cast(LocalDate.class).eq(LocalDate.now())));
    	PaperEntity paperEntity = PaperService.getFromCaches(paperId);
    	if (pcList.size()>=paperEntity.getMaxTimeOneday()) {
    		res.put("code",1);
    		res.put("msg","每天考试次数不能超过" + paperEntity.getMaxTimeOneday() + "次");
    		return res;
    	}
		res.put("code",0);
    	return res;
    }
    @RequestMapping({"/delete"})
    public LayuiTableResponse<PaperCopyEntity> delete(@RequestParam("ids[]") Long[] ids) {
        LayuiTableResponse<PaperCopyEntity> ltr = new LayuiTableResponse<>();
        for (Long id : ids) {
        	PaperCopyEntity m = paperCopyService.getEntityById(id);
        	m.setState(-1);
        	paperCopyService.update(m);
        }
        return ltr;
    }

}
